#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>

class BestEffortSub : public rclcpp::Node {
public:
  BestEffortSub() : Node("best_effort_subscriber_node") {
    auto qos = rclcpp::QoS(rclcpp::KeepLast(10));
    qos.best_effort();
    sub_ = this->create_subscription<std_msgs::msg::String>(
        "best_effort_topic", qos,
        std::bind(&BestEffortSub::topic_callback, this, std::placeholders::_1));
  }
  void topic_callback(const std_msgs::msg::String::SharedPtr msg) {
    RCLCPP_INFO(this->get_logger(), "Received message: '%s'",
                msg->data.c_str());
  }

private:
  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub_;
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<BestEffortSub>());
  rclcpp::shutdown();
  return 0;
}